package net.cdsunrise.com.worker.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @author: LiuWei
 * @date: Create in 10:36 2018/05/24
 */
@Configuration
public class RequestInterceptorConfig implements RequestInterceptor {

    private static final String AUTHORIZATION_HEADER = "Authorization";

//    private static final String BEARER_TOKEN_TYPE = "Bearer";

    /**
     * 设置验证信息
     *
     * @param requestTemplate
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        String Authorization = attributes.getRequest().getHeader(AUTHORIZATION_HEADER);
        requestTemplate.header(AUTHORIZATION_HEADER, Authorization);
    }
}
